package com.ww.springboot.es.service.impl;


import cn.hutool.json.JSON;
import com.ww.springboot.es.dto.ForecastRecord;
import com.ww.springboot.es.en.ForecastBizTypeEnum;
import com.ww.springboot.es.resp.ForecastRecordRepository;
import com.ww.springboot.es.service.IForecastRecordService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author : liw
 * @date : 2020/11/18 19:34
 */
@Service
@AllArgsConstructor
public class ForecastRecordServiceImpl implements IForecastRecordService {


    private final ForecastRecordRepository forecastRecordRepository;

    /**
     * 保存 预报日志
     *
     * @param requestSysName  请求方系统名称
     * @param responseSysName 响应方系统名称
     * @param bizTypeEnum     业务类型
     * @param forecastRecord  预报日志对象
     * @param bizNumber       业务单号
     */
    @Override
    public void saveRecord(String requestSysName,
                           String responseSysName,
                           ForecastBizTypeEnum bizTypeEnum,
                           ForecastRecord forecastRecord, String bizNumber) {
        forecastRecord.setResponseSysName(responseSysName);
        forecastRecord.setRequestSysName(requestSysName);
        forecastRecord.setBizNumber(bizNumber);
        forecastRecord.setBizType(bizTypeEnum.getCode());
        forecastRecord.setUpdateTime(LocalDateTime.now());
        forecastRecordRepository.save(forecastRecord);
    }

    @Override
    public void saveRecordJson(String json, String requestSysName, String responseSysName, ForecastBizTypeEnum bizTypeEnum, ForecastRecord forecastRecord, String bizNumber) {
        forecastRecord.setRequestMessage(json);
        forecastRecord.setResponseSysName(responseSysName);
        forecastRecord.setRequestSysName(requestSysName);
        forecastRecord.setBizNumber(bizNumber);
        forecastRecord.setBizType(bizTypeEnum.getCode());
        forecastRecord.setBizTypeName(bizTypeEnum.getMsg());
        forecastRecord.setUpdateTime(LocalDateTime.now());
        forecastRecordRepository.save(forecastRecord);
    }
}
